# coding:utf-8
import logging
import sys

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication

from config import init_create_table, log_fmt, LogFile
from tools import Logger, get_now_time
from view.image_view import ImageView
import res.res_rc
from model import Thumbnail

logger = Logger('sqlalchemy')
logger.setLogFile(LogFile / 'sqlalchemy{}.log'.format(get_now_time()), log_fmt)
logger.setLevel(logging.INFO)
init_create_table(logger)

QApplication.setHighDpiScaleFactorRoundingPolicy(
    Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

app = QApplication(sys.argv)
app.setQuitOnLastWindowClosed(True)

demo = ImageView()
demo.setWindowIcon(QIcon(':/logo/logo.png'))
demo.setWindowTitle('赤鸢的图片浏览器')
demo.resize(1000, 800)

app.installEventFilter(demo)  # 安装全局事件过滤器
try:
    demo.setImage(sys.argv[1])
except Exception as e:
    logger.error(e)

demo.show()
sys.exit(app.exec_())
